<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Promise</title>
	</head>
	<body>
		<script src="./index3.js"></script>
		<script>
			{
				/**
				 // 基础版 Promise
				 const p1 = new Promise((resolve, reject) => {
				 	console.log('create a promise');
				 	resolve('成功了');
				 })
				 console.log("after new promise");
				 const p2 = p1.then(data => {
				 	console.log(data)
				 	throw new Error('失败了')
				 })
				 const p3 = p2.then(data => {
				 	console.log('success', data)
				 }, err => {
				 	console.log('faild', err)
				 })
				 
				 // "create a promise"
				 // "after new promise"
				 // "成功了"
				 // "faild Error: 失败了"
				 */
			}

			// {
			// 	const promise = new myPromise((resolve, reject) => {
			// 	  // 传入一个异步操作
			// 	  setTimeout(() => {
			// 	    resolve('成功');
			// 	  },1000);
			// 	}).then(
			// 	  (data) => {
			// 	    console.log('success', data)
			// 	  },
			// 	  (err) => {
			// 	    console.log('faild', err)
			// 	  }
			// 	)
			// }

			{
				const promise = new myPromise((resolve, reject) => {
					reject('失败');
				}).then().then().then(data => {
					console.log(data);
				}, err => {
					console.log('err', err);
				})
			}
		</script>
	</body>
</html>